import { getSearchQuery } from '../../utils';
import React, { useEffect, useState } from 'react';
import { AllComponents } from '../../consts/datas';
import styles from './index.module.less';

const Index = ({ comData } = {}) => {
  console.log('comData', comData);

  return (
    <div className={styles.boxWrap}>
      {!comData?.length && <div>空</div>}
      {comData?.map?.((item, i) => {
        const Com = AllComponents[item.type];
        return <Com {...item} key={`${i}`} />;
      })}
    </div>
  );
};

export async function getServerSideProps({ params, ...allData }) {
  const res = allData?.query?.comData;
  // console.log('params>>>>>>>>>>', res);
  let data = [];
  try {
    if (res) {
      data = JSON.parse(res);
    }
  } catch (error) {}
  return {
    props: {
      comData: data,
    },
  };
}

export default Index;
